package com.dataaccess.dataaccess.web.service;

import cn.hutool.core.codec.Base64Decoder;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.HexUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import com.dataaccess.dataaccess.common.base.BaseService;
import com.dataaccess.dataaccess.model.*;
import com.dataaccess.dataaccess.support.model.RespEntity;
import com.dataaccess.dataaccess.support.mybatisplus.QueryWrapper;
import com.dataaccess.dataaccess.support.utils.DateUtils;
import com.dataaccess.dataaccess.support.utils.HexToASCIIUtils;
import com.dataaccess.dataaccess.support.utils.MyLogger;
import com.dataaccess.dataaccess.support.utils.requestutil.HttpRequestUtil;
import com.dataaccess.dataaccess.web.mapper.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.*;

@Service
@Slf4j
public class DeviceAboatFirewaterService extends BaseService {

    @Resource
    public MyLogger logger;
    @Resource
    FirewaterAlarmDeviceDataChangedMapper firewaterAlarmDeviceDataChangedMapper;
    @Resource
    FirewaterNormalDeviceDataChangedMapper firewaterNormalDeviceDataChangedMapper;
    @Resource
    AlarmRecordMapper alarmRecordMapper;
    @Resource
    private FirewatersAlarmDeviceDataChangedMapper firewatersAlarmDeviceDataChangedMapper;
    @Resource
    private FirewatersNormalDeviceDataChangedMapper firewatersNormalDeviceDataChangedMapper;
    @Resource
    NormalRecordMapper normalRecordMapper;
    @Resource
    FirewaterAllDeviceDataChangedMapper firewaterAllDeviceDataChangedMapper;
    @Resource
    private AsyncService asyncService;
    /**
     * 订阅--调用相关接口
     *
     * @param
     * @return
     */
    public RespEntity getInfo(JSONObject jsonParam) {

        return RespEntity.success();
    }

    /**
     * 回调地址--设备信息变化，订阅后推送设备信息变化通知
     *
     * @param
     * @return
     */
    public RespEntity deviceInfoChanged(JSONObject jsonParam) {
        jsonParam = HttpRequestUtil.commonHttpRequestParamConvert(getRequest());
        FirewaterAllDeviceDataChanged firewatersAllDeviceDataChanged = new FirewaterAllDeviceDataChanged();
        firewatersAllDeviceDataChanged.setId(UUID.randomUUID().toString());
        firewatersAllDeviceDataChanged.setJsondata(jsonParam.toString());
        firewatersAllDeviceDataChanged.setType("w");
        firewaterAllDeviceDataChangedMapper.insert(firewatersAllDeviceDataChanged);
        return RespEntity.success();
    }

    /**
     * 回调地址：设备数据变化，订阅后推送设备数据变化通知
     *
     * @param
     * @return
     */
    public RespEntity deviceDataChanged(JSONObject jsonParam) throws Exception {
        logger.info(jsonParam.toString());
        //处理支持form-data和json两种方式
        //jsonParam = HttpRequestUtil.commonHttpRequestParamConvert(getRequest());
        //解析数据开始-------------------------------------------------------------------------------------------------------
        if (jsonParam.containsKey("notify_data")) {
            //世成电器(后边这个几个jsonParam无用)
            return shichengDQ(jsonParam,jsonParam,jsonParam);
        }
        JSONObject service = jsonParam.getJSONObject("service");
        //数据
        JSONObject data = service.getJSONObject("data");
        if (data.containsKey("Pressure")) {
            //泰科
            return ShenzhenTKXY(jsonParam, data, service);
        }else if (data.containsKey("up_date")){
            //世成电器
            return shichengDQ(jsonParam, data, service);
        }else {
            //上海铭空
            return shanghaiMK(jsonParam, data, service);
        }
    }

    /**
     * @Author YangYu
     * @Description 消防用水-设备服务(世成电器)
     * @Date Created in 11:23 2020/12/7
     * @Param [jsonParam, data, service]
     */

    public RespEntity shichengDQ(JSONObject jsonParam, JSONObject data, JSONObject service) throws Exception {
        logger.info("-------------------------世成电器：" + jsonParam + "-------------------------------");
        //报警数据
        String receivePiezoMeter = "";
        //报警时间
        String event_time = "";
        if (jsonParam.containsKey("notify_data")) {
            //世成电器
            JSONObject notify_data = jsonParam.getJSONObject("notify_data");
            JSONArray services = notify_data.getJSONArray("services");
            JSONObject bigdata = (JSONObject) services.get(0);
            data = bigdata.getJSONObject("data");
            //报警数据
            receivePiezoMeter = data.getStr("ReceivePiezoMeter");
            //报警时间
            event_time = contextLoads(bigdata.getStr("event_time"));
        }else {
            //报警时间
            event_time = contextLoads(service.getStr("eventTime"));
            //报警数据
            receivePiezoMeter = data.getStr("up_date");
        }

        //液位、液压表示
        String flag = receivePiezoMeter.substring(6, 9);
        //设备号
        String number = receivePiezoMeter.substring(9, 24);
        //报警状态
        String alarmStatus = receivePiezoMeter.substring(24, 26);
        //最低值
        String lowestValue = receivePiezoMeter.substring(26, 30);
        //最高值
        String highestValue = receivePiezoMeter.substring(30, 34);
        //当前值 NB900490486433304710124104011002000265NC
        String currentValue = receivePiezoMeter.substring(34, 38);
        String kpaN = "";
        if (currentValue.substring(0, 4).equals("0000")){
            kpaN = "0";
        }else if (currentValue.substring(0, 3).equals("000")){
            kpaN = currentValue.substring(3, 4);
        }else if (currentValue.substring(0, 2).equals("00")){
            kpaN = currentValue.substring(2, 4);
        }else if (currentValue.substring(0, 1).equals("0")){
            kpaN = currentValue.substring(1, 4);
        }else {
            kpaN = currentValue;
        }

        //报警类型
        String alarmTypeName = "";
        //报警内容
        String content = "";
        //消防支队数据
        String alarmStr = "";
        //报警表示
        boolean alarmFlag = false;
        JSONObject jsonParamItemMap = new JSONObject();
        //imei号，即应用平台的设备号
        jsonParamItemMap.put("number", number);
        //检测项数值
        Map<String, String> itemMap = getItme(jsonParamItemMap);
        if (itemMap.isEmpty()) {
            return RespEntity.fail("设备不存在!");
        }
        double dbMpa = 0;
        //正常数据信息
        JSONObject jSONObject = new JSONObject();
        JSONArray jSONArray = new JSONArray();
        if (flag.equals("902")) {//液压
            //报警值
            dbMpa = Double.parseDouble(kpaN) / 1000;
//            if (alarmStatus.equals("02")) {
//                alarmTypeName = "液压报警";
//                content = "电量不足";
//                alarmFlag = true;
//            }
//            if (alarmStatus.equals("03")) {
//                alarmTypeName = "液压报警";
//                content = "低压报警 " + "报警值:" + dbMpa + "MPa";
//                alarmFlag = true;
//            }
//            if (alarmStatus.equals("04")) {
//                alarmTypeName = "液压报警";
//                content = "高压报警 " + "报警值:" + dbMpa + "MPa";
//                alarmFlag = true;
//            }
            if (dbMpa > Double.parseDouble(itemMap.get("液压报警;max")) || dbMpa < Double.parseDouble(itemMap.get("液压报警;min"))) {
                alarmFlag = true;
                alarmTypeName = "液压报警";
                content = "水压报警 " + "报警值:" + dbMpa + "MPa";
                alarmStr = "3002" + ";;" + dbMpa + ";;" + "水压异常";
            }
            jSONObject.put("name", "水压");
            jSONObject.put("value", dbMpa);
            jSONArray.add(jSONObject);

        } else {//液位
            //报警值
            dbMpa = Double.parseDouble(kpaN) / 100;
//            if (alarmStatus.equals("02")) {
//                alarmTypeName = "液位报警";
//                content = "电量不足";
//                alarmFlag = true;
//            }
//            if (alarmStatus.equals("03")) {
//                alarmTypeName = "液位报警";
//                content = "低水位报警 " + "报警值:" + dbMpa + "m";
//                alarmFlag = true;
//            }
//            if (alarmStatus.equals("04")) {
//                alarmTypeName = "液位报警";
//                content = "高水位报警 " + "报警值:" + dbMpa + "m";
//                alarmFlag = true;
//            }
            if (dbMpa < Double.parseDouble(itemMap.get("液位报警;min"))) {
                alarmTypeName = "液位报警";
                content = "水位报警 " + "报警值:" + dbMpa + "m";
                alarmFlag = true;
                alarmStr = "3102" + ";;" + dbMpa + ";;" + "水位异常";
            }
            jSONObject.put("name", "当前水位");
            jSONObject.put("value", dbMpa);
            jSONArray.add(jSONObject);

        }
        JSONObject jsonParamN = new JSONObject();
        jsonParamN.put("number", number);
        //为报警
        if (alarmFlag) {
            boolean insertAlarmFlag = false;
            //查询这个设备号这种类型的报警上次报警时间，如果时间间隔在2小时以内，不报警
            List<AlarmRecord> alarmList = alarmRecordMapper.selectList(new QueryWrapper<AlarmRecord>().eq("number", number).eq("type", alarmTypeName));
            if (alarmList.isEmpty()) {//没有记录时添加
                AlarmRecord alarmRecord = new AlarmRecord();
                alarmRecord.setNumber(number);
                alarmRecord.setTime(DateUtil.now());
                alarmRecord.setType(alarmTypeName);
                alarmRecordMapper.insert(alarmRecord);
                insertAlarmFlag = true;
            } else {//有记录时判断加修改
                AlarmRecord alarmRecord = alarmList.get(0);
                String times = alarmRecord.getTime();
                SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                boolean timeFlag = DateUtils.judgmentDate(times,6);
                if (timeFlag) {
                    alarmRecord.setTime(DateUtil.now());
                    alarmRecordMapper.update(alarmRecord, new QueryWrapper<AlarmRecord>().eq("number", number).eq("type", alarmTypeName));
                    insertAlarmFlag = true;
                }
            }
            if (insertAlarmFlag) {
                //存储在数据库
                FirewatersAlarmDeviceDataChanged firewatersAlarmDeviceDataChanged = new FirewatersAlarmDeviceDataChanged();
                firewatersAlarmDeviceDataChanged.setId(UUID.randomUUID().toString());
                firewatersAlarmDeviceDataChanged.setJsondata(jsonParam.toString());
                firewatersAlarmDeviceDataChangedMapper.insert(firewatersAlarmDeviceDataChanged);
                jsonParamN.put("interfaceType", "1");
                jsonParamN.put("content", content);
                jsonParamN.put("alarmTypeName", alarmTypeName);
                jsonParamN.put("alarmtime", event_time);
                jsonParamN.put("deviceClassify", 2);
                jsonParamN.put("alarmStr", alarmStr);
                fireFightingiot(jsonParamN, "communication", "notificationAlarmHandel", "alarmInfo");
                //异步更新设备状态
                jsonParamN.put("state","2");
                asyncService.updateDeviceCurrentState(jsonParamN);
            }
        }else {
            //异步更新设备状态
            jsonParamN.put("state","1");
            asyncService.updateDeviceCurrentState(jsonParamN);
        }
        //存储在数据库
        FirewatersNormalDeviceDataChanged firewatersNormalDeviceDataChanged = new FirewatersNormalDeviceDataChanged();
        firewatersNormalDeviceDataChanged.setId(UUID.randomUUID().toString());
        firewatersNormalDeviceDataChanged.setJsondata(jsonParam.toString());
        firewatersNormalDeviceDataChangedMapper.insert(firewatersNormalDeviceDataChanged);
        //rest调用平时数据添加接口：
        jsonParamN.put("paraminfo", jSONArray);
        jsonParamN.put("time", event_time);
        //return RespEntity.success(jsonParamN);
        fireFightingiot(jsonParamN, "firefightingiot_data", "normalInfo", "device");
        //异步维护水设备最新一包数据
        asyncService.updateWaterDeviceValue(jsonParamN);
        //解析数据结束-------------------------------------------------------------------------------------------------------
        return RespEntity.success();
    }

    /**
     * 消防用水-设备服务(上海铭控)
     *
     * @param jsonParam
     * @return
     * @throws Exception
     */
    public RespEntity shanghaiMK(JSONObject jsonParam, JSONObject data, JSONObject service) throws Exception {
        logger.info("-------------------------上海铭控：" + jsonParam + "-------------------------------");
        //设备号
        String number = data.getStr("deviceId");
        //时间
        String time = contextLoads(service.getStr("eventTime"));
        //报警状态
        String str = data.getStr("alarmStatus");
        String alarmStatus = str.replaceAll(" ", "");
        //当前水压/水位
        String currentData = data.getStr("currentData");
        //设备类型
        String unitSymbol = data.getStr("unitSymbol");
        //报警内容
        String content = "";
        //接口类型：1 设备报警 2 消除报警
        String interfaceType = "";
        JSONObject jsonParamN = new JSONObject();
        //imei号，即应用平台的设备号
        jsonParamN.put("number", number);
        String alarmStr = "";
        //检测项数值
        Map<String, String> itemMap = getItme(jsonParamN);
        if (itemMap.isEmpty()) {
            return RespEntity.fail("设备不存在!");
        }
        //报警类型
        String alarmTypeName = "";
        boolean alarmFlag = false;
        if (unitSymbol.contains("压力")) {
            alarmTypeName = "液压报警";
            alarmStr = "3002" + ";;" + currentData + ";;" + "水压异常";
            //content = alarmStatus + " 报警值:" + currentData + "MPa";
            if (Double.parseDouble(currentData) > Double.parseDouble(itemMap.get("液压报警;max")) || Double.parseDouble(currentData) < Double.parseDouble(itemMap.get("液压报警;min"))) {
                content = "水压报警 " + "报警值:" + currentData + "MPa";
                alarmFlag = true;
            }
        }
        if (unitSymbol.contains("液位")) {
            alarmTypeName = "液位报警";
            alarmStr = "3102" + ";;" + currentData + ";;" + "水位异常";
            //content = alarmStatus + " 报警值:" + currentData + "m";
            if (Double.parseDouble(currentData) < Double.parseDouble(itemMap.get("液位报警;min"))) {
                content = "水位报警 " + "报警值:" + currentData + "m";
                alarmFlag = true;
            }
        }
        //为报警
        boolean insertAlarmFlag = false;
        if (alarmFlag) {
            logger.info(jsonParam.toString());
            logger.info("-------------------------------------------------------------------------不正常--------------------------------------------------------------------------------");
            logger.info("-------------------------------------------------------------------------不正常--------------------------------------------------------------------------------");
            //查询这个设备号这种类型的报警上次报警时间，如果时间间隔在2小时以内，不报警
            List<AlarmRecord> alarmList = alarmRecordMapper.selectList(new QueryWrapper<AlarmRecord>().eq("number", number).eq("type", alarmTypeName));
            if (alarmList.isEmpty()) {//没有记录时添加
                AlarmRecord alarmRecord = new AlarmRecord();
                alarmRecord.setNumber(number);
                alarmRecord.setTime(DateUtil.now());
                alarmRecord.setType(alarmTypeName);
                alarmRecordMapper.insert(alarmRecord);
                insertAlarmFlag = true;
            } else {//有记录时判断加修改
                AlarmRecord alarmRecord = alarmList.get(0);
                String times = alarmRecord.getTime();
                SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                boolean timeFlag = DateUtils.judgmentDate(times,6);
                if (timeFlag) {
                    alarmRecord.setTime(DateUtil.now());
                    alarmRecordMapper.update(alarmRecord, new QueryWrapper<AlarmRecord>().eq("number", number).eq("type", alarmTypeName));
                    insertAlarmFlag = true;
                }
            }
            if (insertAlarmFlag) {
                //接口类型：1 设备报警 2 消除报警
                interfaceType = "1";
                //存储在数据库
                FirewatersAlarmDeviceDataChanged firewatersAlarmDeviceDataChanged = new FirewatersAlarmDeviceDataChanged();
                firewatersAlarmDeviceDataChanged.setId(UUID.randomUUID().toString());
                firewatersAlarmDeviceDataChanged.setJsondata(jsonParam.toString());
                firewatersAlarmDeviceDataChangedMapper.insert(firewatersAlarmDeviceDataChanged);
                //rest调用通知模块接口：
                jsonParamN.put("interfaceType", interfaceType);
                jsonParamN.put("content", content);
                jsonParamN.put("alarmTypeName", alarmTypeName);
                jsonParamN.put("alarmtime", time);
                jsonParamN.put("deviceClassify", 2);
                jsonParamN.put("alarmStr", alarmStr);
                //return RespEntity.success(jsonParamN);
                fireFightingiot(jsonParamN, "communication", "notificationAlarmHandel", "alarmInfo");
                //异步更新设备状态
                jsonParamN.put("state","2");
                asyncService.updateDeviceCurrentState(jsonParamN);
            }
        } else {
            //异步更新设备状态
            jsonParamN.put("state","1");
            asyncService.updateDeviceCurrentState(jsonParamN);
        }
        //报警信息
        JSONObject jSONObject = new JSONObject();
        JSONArray jSONArray = new JSONArray();
        if (unitSymbol.contains("压力")) {
            //String unitSymbols = unitSymbol.replace("压力表","").replace("MPa","").trim();
            jSONObject.put("name", "水压");
            jSONObject.put("value", currentData);
            jSONArray.add(jSONObject);
        }
        if (unitSymbol.contains("液位")) {
            //String unitSymbols = unitSymbol.replace("液位表","").replace("m","").trim();
            jSONObject.put("name", "当前水位");
            jSONObject.put("value", currentData);
            jSONArray.add(jSONObject);
        }
        //查询这个设备号上次平时数据的时间，如果时间间隔在0.25小时以内，不发送
            /*List<NormalRecord> normalList = normalRecordMapper.selectList(new QueryWrapper<NormalRecord>().eq("number",number));
            if(normalList.isEmpty()){//没有记录时添加
                NormalRecord normalRecord = new NormalRecord();
                normalRecord.setNumber(number);
                normalRecord.setTime(DateUtil.now());
                normalRecordMapper.insert(normalRecord);
            }else{//有记录时判断加修改
                NormalRecord normalRecord = normalList.get(0);
                String times  = normalRecord.getTime();
                SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                boolean timeFlag = getDatePoor(new Date(),simpleDateFormat.parse(times),0.25);
                if(timeFlag){
                    normalRecord.setTime(DateUtil.now());
                    normalRecordMapper.update(normalRecord,new QueryWrapper<NormalRecord>().eq("number",number));
                }else{
                    return RespEntity.success();
                }
            }*/
        //存储在数据库
        FirewatersNormalDeviceDataChanged firewatersNormalDeviceDataChanged = new FirewatersNormalDeviceDataChanged();
        firewatersNormalDeviceDataChanged.setId(UUID.randomUUID().toString());
        firewatersNormalDeviceDataChanged.setJsondata(jsonParam.toString());
        firewatersNormalDeviceDataChangedMapper.insert(firewatersNormalDeviceDataChanged);
        //rest调用平时数据添加接口：
        jsonParamN.put("paraminfo", jSONArray);
        jsonParamN.put("time", time);
        //return RespEntity.success(jsonParamN);
        fireFightingiot(jsonParamN, "firefightingiot_data", "normalInfo", "device");
        //大数据
        jsonParamN.put("dataType", "2");
        fireFightingiot(jsonParamN, "communication", "notificationAlarmHandel", "alarmInfo");
        //异步维护水设备最新一包数据
        asyncService.updateWaterDeviceValue(jsonParamN);
        //解析数据结束-------------------------------------------------------------------------------------------------------
        return RespEntity.success();
    }

    /**
     * 消防用水-设备服务(深圳泰科芯元)
     *
     * @param jsonParam
     * @param data
     * @param service
     * @return
     * @throws Exception
     */
    public RespEntity ShenzhenTKXY(JSONObject jsonParam, JSONObject data, JSONObject service) throws Exception {
        logger.info("-------------------------圳泰科芯元：" + jsonParam + "-------------------------------");
        //服务id
        String serviceId = service.getStr("serviceId");
        //事件事件
        String time = contextLoads(service.getStr("eventTime"));
        //具体数据信息
        String pressure = data.getStr("Pressure");
        String pressures = pressure.substring(1, 35);
        String strs[] = pressures.split(":");
        //压力值
        String kpa = strs[1];
        //电压
        String v = strs[2];
        //设备类型
        String deviceType = pressures.substring(0, 1);
        String alarmTypeName = "";
        if ("C".equals(deviceType)) {
            alarmTypeName = "室外消火栓";
        }
        if ("D".equals(deviceType)) {
            alarmTypeName = "管道压力";
        }
        if ("E".equals(deviceType)) {
            alarmTypeName = "水箱液位压力";
        }
        if ("F".equals(deviceType)) {
            alarmTypeName = "灭火器压力";
        }
        if ("G".equals(deviceType)) {
            alarmTypeName = "水浸报警";
        }
        if ("H".equals(deviceType)) {
            alarmTypeName = "温湿度";
        }
        String signa = pressures.substring(28, 29);
        String signas = "";
        if ("0".equals(signa)) {
            signas = "正常";
        }
        if ("1".equals(signa)) {
            signas = "漏水";
        }
        if ("2".equals(signa)) {
            signas = "放水阀动作";
        }
        if ("8".equals(signa)) {
            signas = "放水传感器故障";
        }
        String signb = pressures.substring(29, 30);
        //报警类型
        String AlarmType = "";
        String AlarmCode = "";
        String signbs = "";
        if ("0".equals(signb)) {
            signbs = "正常";
        }
        if ("1".equals(signb)) {
            signbs = "撞击报警";
        }
        if ("2".equals(signb)) {
            signbs = "开盖报警";
        }
        if ("8".equals(signb)) {
            signbs = "撞击传感器故障";
        }
        String signc = pressures.substring(30, 31);
        String signcs = "";
        if ("0".equals(signc)) {
            signcs = "压力正常";
            AlarmType = "压力正常";
            AlarmCode = "3003";
        }
        if ("1".equals(signc)) {
            signcs = "压力低于下限阀值";
            AlarmType = "欠压报警";
            AlarmCode = "3001";
        }
        if ("2".equals(signc)) {
            signcs = "压力高于上限阀值";
            AlarmType = "过压报警";
            AlarmCode = "3002";
        }
        if ("4".equals(signc)) {
            signcs = "压力传感器故障";
        }
        String signd = pressures.substring(31, 32);
        String signds = "";
        if ("0".equals(signd)) {
            signds = "正常";
        }
        if ("1".equals(signd)) {
            signds = "表示电池电压低";
        }
        if ("4".equals(signd)) {
            signds = "表示子设备失联";
        }
        //报警内容
        String content = "";
        //设备号
        String number = pressures.substring(1, 16);
        String alarmStr = "";
        //接口类型：1 设备报警 2 消除报警
        String interfaceType = "";
        JSONObject jsonParamN = new JSONObject();
        //imei号，即应用平台的设备号
        jsonParamN.put("number", number);
        //检测项数值
        Map<String, String> itemMap = getItme(jsonParamN);
        if (itemMap.isEmpty()) {
            return RespEntity.fail("设备不存在!");
        }
        //报警类型
        String type = pressures.substring(28, 32);
        boolean alarmFlag = false;
        //水压
        double dbKpa = 0;
        //水位
        double m = 0;
        if ("D".equals(deviceType) || "C".equals(deviceType)) {
            if (StrUtil.isNotBlank(kpa) && kpa.length() == 5) {
                String kpaN = kpa.substring(0, 4);
                if (kpa.substring(0, 4).equals("0000")) kpaN = "0";
                if (kpa.substring(0, 3).equals("000")) kpaN = kpa.substring(3, 4);
                if (kpa.substring(0, 2).equals("00")) kpaN = kpa.substring(2, 4);
                if (kpa.substring(0, 1).equals("0")) kpaN = kpa.substring(1, 4);
                dbKpa = Double.parseDouble(kpaN) / 1000;
            } else {
                return RespEntity.fail("水压格式不对！");
            }
            if (dbKpa > Double.parseDouble(itemMap.get("液压报警;max")) || dbKpa < Double.parseDouble(itemMap.get("液压报警;min"))) {
                alarmFlag = true;
                content = "水压报警 " + "报警值:" + dbKpa + "MPa";
                alarmStr = "3002" + ";;" + dbKpa + ";;" + "水压异常";
            }
        } else if ("E".equals(deviceType)) {
            if (StrUtil.isNotBlank(kpa)) {
                kpa = kpa.substring(0, kpa.length() - 1);
                m = Double.parseDouble(kpa) / 10;
                if (m < Double.parseDouble(itemMap.get("液位报警;min"))) {
                    alarmFlag = true;
                    content = "水位报警 " + "报警值:" + dbKpa + "m";
                    alarmStr = "3102" + ";;" + dbKpa + ";;" + "水位异常";
                }
            }
        }
        //为报警
        boolean insertAlarmFlag = false;
        if (alarmFlag) {
            logger.info(jsonParam.toString());
            logger.info("-------------------------------------------------------------------------!0000--------------------------------------------------------------------------------");
            logger.info("-------------------------------------------------------------------------!0000--------------------------------------------------------------------------------");
            //查询这个设备号这种类型的报警上次报警时间，如果时间间隔在2小时以内，不报警
            List<AlarmRecord> alarmList = alarmRecordMapper.selectList(new QueryWrapper<AlarmRecord>().eq("number", number).eq("type", alarmTypeName));
            if (alarmList.isEmpty()) {//没有记录时添加
                AlarmRecord alarmRecord = new AlarmRecord();
                alarmRecord.setNumber(number);
                alarmRecord.setTime(DateUtil.now());
                alarmRecord.setType(alarmTypeName);
                alarmRecordMapper.insert(alarmRecord);
                insertAlarmFlag = true;
            } else {//有记录时判断加修改
                AlarmRecord alarmRecord = alarmList.get(0);
                String times = alarmRecord.getTime();
                SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                boolean timeFlag = DateUtils.judgmentDate(times,6);
                if (timeFlag) {
                    alarmRecord.setTime(DateUtil.now());
                    alarmRecordMapper.update(alarmRecord, new QueryWrapper<AlarmRecord>().eq("number", number).eq("type", alarmTypeName));
                    insertAlarmFlag = true;
                }
            }
            if (insertAlarmFlag) {
                //接口类型：1 设备报警 2 消除报警
                interfaceType = "1";
                //存储在数据库
                FirewaterAlarmDeviceDataChanged firewaterAlarmDeviceDataChanged = new FirewaterAlarmDeviceDataChanged();
                firewaterAlarmDeviceDataChanged.setId(UUID.randomUUID().toString());
                firewaterAlarmDeviceDataChanged.setJsondata(jsonParam.toString());
                firewaterAlarmDeviceDataChangedMapper.insert(firewaterAlarmDeviceDataChanged);
                //rest调用通知模块接口：
                jsonParamN.put("interfaceType", interfaceType);
                jsonParamN.put("content", content);
                jsonParamN.put("alarmTypeName", alarmTypeName);
                jsonParamN.put("alarmtime", time);
                jsonParamN.put("deviceClassify", 2);
                jsonParamN.put("alarmStr", alarmStr);
                //return RespEntity.success(jsonParamN);
                fireFightingiot(jsonParamN, "communication", "notificationAlarmHandel", "alarmInfo");
                //异步更新设备状态
                jsonParamN.put("state","2");
                asyncService.updateDeviceCurrentState(jsonParamN);
            }
        } else {
            //异步更新设备状态
            jsonParamN.put("state","1");
            asyncService.updateDeviceCurrentState(jsonParamN);
        }
        //报警信息
        JSONObject jSONObject = new JSONObject();
        JSONArray jSONArray = new JSONArray();
        if ("D".equals(deviceType)|| "C".equals(deviceType)) {
            jSONObject.put("name", "水压");
            jSONObject.put("value", dbKpa);
            jSONArray.add(jSONObject);
            jsonParamN.put("value", dbKpa);
        }
        if ("E".equals(deviceType)) {
            jSONObject.put("name", "当前水位");
            jSONObject.put("value", m);
            jSONArray.add(jSONObject);
            jsonParamN.put("value", m);
        }
        //查询这个设备号上次平时数据的时间，如果时间间隔在0.25小时以内，不发送
            /*List<NormalRecord> normalList = normalRecordMapper.selectList(new QueryWrapper<NormalRecord>().eq("number",number));
            if(normalList.isEmpty()){//没有记录时添加
                NormalRecord normalRecord = new NormalRecord();
                normalRecord.setNumber(number);
                normalRecord.setTime(DateUtil.now());
                normalRecordMapper.insert(normalRecord);
            }else{//有记录时判断加修改
                NormalRecord normalRecord = normalList.get(0);
                String times  = normalRecord.getTime();
                SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                boolean timeFlag = getDatePoor(new Date(),simpleDateFormat.parse(times),0.25);
                if(timeFlag){
                    normalRecord.setTime(DateUtil.now());
                    normalRecordMapper.update(normalRecord,new QueryWrapper<NormalRecord>().eq("number",number));
                }else{
                    return RespEntity.success();
                }
            }*/
        //存储在数据库
        FirewaterNormalDeviceDataChanged firewaterNormalDeviceDataChanged = new FirewaterNormalDeviceDataChanged();
        firewaterNormalDeviceDataChanged.setId(UUID.randomUUID().toString());
        firewaterNormalDeviceDataChanged.setJsondata(jsonParam.toString());
        firewaterNormalDeviceDataChangedMapper.insert(firewaterNormalDeviceDataChanged);
        //rest调用平时数据添加接口：
        jsonParamN.put("paraminfo", jSONArray);
        jsonParamN.put("time", time);
        fireFightingiot(jsonParamN, "firefightingiot_data", "normalInfo", "device");
        //大数据
        jsonParamN.put("dataType", "2");
        fireFightingiot(jsonParamN, "communication", "notificationAlarmHandel", "alarmInfo");
        //异步维护水设备最新一包数据
        asyncService.updateWaterDeviceValue(jsonParamN);
        //解析数据结束-------------------------------------------------------------------------------------------------------
        return RespEntity.success();
    }

    /**
     * @Author YangYu
     * @Description 世成电器lora
     * @Date Created in 10:43 2021/11/24
     * @Param [jsonParam]
     */

    public RespEntity scdqLORA(JSONObject jsonParam)  {
        //原始数据
        String data = jsonParam.getStr("code");
        //设备号aaaa000101011e00 00ff 000a 00cb006400ff000000001aff5555
        String number = Integer.toString(hexToInt(data.substring(4,8)));
        //设备类型 01压力 02液位
        String deviceType = data.substring(8,10);
        //电量(需要转为10进制+%)
        String electricity = data.substring(12,14);
        Integer electricitys = Integer.parseInt(electricity,16);
        //报警状态（如果不是00需要转成二进制）
        String alarmS = data.substring(14,16);
        String alarm = hexToBinaryString(alarmS);
        //时间
        String time = DateUtil.now();
        //实时数据
        String realTimeData = data.substring(24,28);
        Integer x = Integer.parseInt(realTimeData,16);
        //转换后的实时数据
        DecimalFormat df = new DecimalFormat("#.##");
        String mpOrm = df.format((float)x/100);
        //最终推送数据
        JSONObject jsonParamN = new JSONObject();
        jsonParamN.put("number", number);
        //正常数据信息
        JSONObject jSONObject = new JSONObject();
        JSONArray jSONArray = new JSONArray();
        //报警标识
        boolean insertAlarmFlag = false;
        //报警类型
        String alarmTypeName = "";
        //报警内容
        String content = "";
        //01水压
        if (deviceType.equals("01")){
            if (alarm.charAt(0) == '1'){
                insertAlarmFlag = true;
                alarmTypeName = "水压电量低";
                content = "电池电量低 "+"报警值:"+electricitys+"%";
            }else if (alarm.charAt(1) == '1'){
                insertAlarmFlag = true;
                alarmTypeName = "压力高于上限阀值";
                content = "压力高于上限阀值 "+"报警值:"+mpOrm+"MP";
            }else if (alarm.charAt(2) == '1'){
                insertAlarmFlag = true;
                alarmTypeName = "压力低于下限阀值";
                content = "压力低于下限阀值 "+"报警值:"+mpOrm+"MP";
            }
            jSONObject.put("name", "水压");
            jSONObject.put("value", mpOrm);
            jSONArray.add(jSONObject);
        }else {
            if (alarm.charAt(0) == '1'){
                insertAlarmFlag = true;
                alarmTypeName = "水位电量低";
                content = "电池电量低 "+"报警值:"+electricitys+"%";
            }else if (alarm.charAt(1) == '1'){
                insertAlarmFlag = true;
                alarmTypeName = "液位报警";
                content = "液位高于上限阀值 "+"报警值:"+mpOrm+"M";
            }else if (alarm.charAt(2) == '1'){
                insertAlarmFlag = true;
                alarmTypeName = "液位报警";
                content = "液位低于下限阀值 "+"报警值:"+mpOrm+"M";
            }
            jSONObject.put("name", "当前水位");
            jSONObject.put("value", mpOrm);
            jSONArray.add(jSONObject);
        }
        if (insertAlarmFlag) {
            jsonParamN.put("interfaceType", "1");
            jsonParamN.put("content", content);
            jsonParamN.put("alarmTypeName", alarmTypeName);
            jsonParamN.put("alarmtime", time);
            jsonParamN.put("deviceClassify", 2);
            jsonParamN.put("alarmStr", "3002" + ";;" + mpOrm + ";;" + "水压异常");
            fireFightingiot(jsonParamN, "communication", "notificationAlarmHandel", "alarmInfo");
            //异步更新设备状态
            jsonParamN.put("state","2");
            asyncService.updateDeviceCurrentState(jsonParamN);
        }else {
            //异步更新设备状态
            jsonParamN.put("state","1");
            asyncService.updateDeviceCurrentState(jsonParamN);
        }
        //rest调用平时数据添加接口：
        jsonParamN.put("paraminfo", jSONArray);
        jsonParamN.put("time", time);
        fireFightingiot(jsonParamN, "firefightingiot_data", "normalInfo", "device");
        //异步维护水设备最新一包数据
        asyncService.updateWaterDeviceValue(jsonParamN);
        //解析数据结束-------------------------------------------------------------------------------------------------------
        return RespEntity.success();
    }

    /**
     * @Author YangYu
     * @Description 世成电器水设备（电信）
     * @Date Created in 10:14 2023/2/4
     * @Param [jsonParam, data, service]
     */

    public RespEntity shichengDX(JSONObject jsonParam) throws Exception {
        //设备号
        String number = jsonParam.getStr("IMEI");
        //报警时间
        String time = contextLoads(jsonParam.getLong("timestamp"));
        //数据
        String data = convertHexToString(HexUtil.encodeHexStr(Base64Decoder.decode(jsonParam.getJSONObject("payload").getStr("APPdata"))));
        //液位、液压表示
        String deviceType = data.substring(6,9);
        //当前值
        String currentValue = data.substring(34,38);
        String kpaN = "";
        if (currentValue.substring(0, 4).equals("0000")){
            kpaN = "0";
        }else if (currentValue.substring(0, 3).equals("000")){
            kpaN = currentValue.substring(3, 4);
        }else if (currentValue.substring(0, 2).equals("00")){
            kpaN = currentValue.substring(2, 4);
        }else if (currentValue.substring(0, 1).equals("0")){
            kpaN = currentValue.substring(1, 4);
        }else {
            kpaN = currentValue;
        }

        //报警类型
        String alarmTypeName = "";
        //报警内容
        String content = "";
        //消防支队数据
        String alarmStr = "";
        //报警表示
        boolean alarmFlag = false;
        JSONObject jsonParamItemMap = new JSONObject();
        //imei号，即应用平台的设备号
        jsonParamItemMap.put("number", number);
        //检测项数值
        Map<String, String> itemMap = getItme(jsonParamItemMap);
        if (itemMap.isEmpty()) {
            return RespEntity.fail("设备不存在!");
        }
        double dbMpa = 0;
        //正常数据信息
        JSONObject jSONObject = new JSONObject();
        JSONArray jSONArray = new JSONArray();
        if (deviceType.equals("902")) {//液压
            //报警值
            dbMpa = Double.parseDouble(kpaN) / 1000;
            if (dbMpa > Double.parseDouble(itemMap.get("液压报警;max"))) {
                alarmFlag = true;
                alarmTypeName = "液压报警";
                content = "水压高于上限阀值 " + "报警值:" + dbMpa + "MPa";
                alarmStr = "3002" + ";;" + dbMpa + ";;" + "水压异常";
            }else if (dbMpa < Double.parseDouble(itemMap.get("液压报警;min"))){
                alarmFlag = true;
                alarmTypeName = "液压报警";
                content = "水压低于下限阀值 " + "报警值:" + dbMpa + "MPa";
                alarmStr = "3002" + ";;" + dbMpa + ";;" + "水压异常";
            }
            jSONObject.put("name", "水压");
            jSONObject.put("value", dbMpa);
            jSONArray.add(jSONObject);

        } else {//液位
            //报警值
            dbMpa = Double.parseDouble(kpaN) / 100;
            if (dbMpa < Double.parseDouble(itemMap.get("液位报警;min"))) {
                alarmTypeName = "液位报警";
                content = "水位报警 " + "报警值:" + dbMpa + "m";
                alarmFlag = true;
                alarmStr = "3102" + ";;" + dbMpa + ";;" + "水位异常";
            }
            jSONObject.put("name", "当前水位");
            jSONObject.put("value", dbMpa);
            jSONArray.add(jSONObject);

        }
        JSONObject jsonParamN = new JSONObject();
        jsonParamN.put("number", number);
        //为报警
        if (alarmFlag) {
            boolean insertAlarmFlag = false;
            //查询这个设备号这种类型的报警上次报警时间，如果时间间隔在2小时以内，不报警
            List<AlarmRecord> alarmList = alarmRecordMapper.selectList(new QueryWrapper<AlarmRecord>().eq("number", number).eq("type", alarmTypeName));
            if (alarmList.isEmpty()) {//没有记录时添加
                AlarmRecord alarmRecord = new AlarmRecord();
                alarmRecord.setNumber(number);
                alarmRecord.setTime(DateUtil.now());
                alarmRecord.setType(alarmTypeName);
                alarmRecordMapper.insert(alarmRecord);
                insertAlarmFlag = true;
            } else {//有记录时判断加修改
                AlarmRecord alarmRecord = alarmList.get(0);
                String times = alarmRecord.getTime();
                SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                boolean timeFlag = DateUtils.judgmentDate(times,0.5);
                if (timeFlag) {
                    alarmRecord.setTime(DateUtil.now());
                    alarmRecordMapper.update(alarmRecord, new QueryWrapper<AlarmRecord>().eq("number", number).eq("type", alarmTypeName));
                    insertAlarmFlag = true;
                }
            }
            if (insertAlarmFlag) {
                //存储在数据库
                FirewatersAlarmDeviceDataChanged firewatersAlarmDeviceDataChanged = new FirewatersAlarmDeviceDataChanged();
                firewatersAlarmDeviceDataChanged.setId(UUID.randomUUID().toString());
                firewatersAlarmDeviceDataChanged.setJsondata(jsonParam.toString());
                firewatersAlarmDeviceDataChangedMapper.insert(firewatersAlarmDeviceDataChanged);
                jsonParamN.put("interfaceType", "1");
                jsonParamN.put("number", number);
                jsonParamN.put("content", content);
                jsonParamN.put("alarmTypeName", alarmTypeName);
                jsonParamN.put("alarmtime", time);
                jsonParamN.put("deviceClassify", 2);
                jsonParamN.put("alarmStr", alarmStr);
                fireFightingiot(jsonParamN, "communication", "notificationAlarmHandel", "alarmInfo");
                //异步更新设备状态
                jsonParamN.put("state","2");
                asyncService.updateDeviceCurrentState(jsonParamN);
            }
        }else {
            //异步更新设备状态
            jsonParamN.put("state","1");
            asyncService.updateDeviceCurrentState(jsonParamN);
        }
        //存储在数据库
        FirewatersNormalDeviceDataChanged firewatersNormalDeviceDataChanged = new FirewatersNormalDeviceDataChanged();
        firewatersNormalDeviceDataChanged.setId(UUID.randomUUID().toString());
        firewatersNormalDeviceDataChanged.setJsondata(jsonParam.toString());
        firewatersNormalDeviceDataChangedMapper.insert(firewatersNormalDeviceDataChanged);
        //rest调用平时数据添加接口：
        jsonParamN.put("paraminfo", jSONArray);
        jsonParamN.put("time", time);
        //return RespEntity.success(jsonParamN);
        fireFightingiot(jsonParamN, "firefightingiot_data", "normalInfo", "device");
        //异步维护水设备最新一包数据
        asyncService.updateWaterDeviceValue(jsonParamN);
        //解析数据结束-------------------------------------------------------------------------------------------------------
        return RespEntity.success();
    }

    /**
     * @Author YangYu
     * @Description 世成电器水设备（电信新协议）
     * @Date Created in 10:14 2023/2/4
     * @Param [jsonParam, data, service]
     */

    public RespEntity shichengDX_new(JSONObject jsonParam) throws Exception {
        //设备号
        String number = jsonParam.getStr("IMEI");
        //报警时间
        String time = contextLoads(jsonParam.getLong("timestamp"));
        //数据
        String data = convertHexToString(HexUtil.encodeHexStr(Base64Decoder.decode(jsonParam.getJSONObject("payload").getStr("APPdata"))));
        //液位、液压表示
        String deviceType = data.substring(2,5);
        // 电话卡号
        String hccid = data.substring(25,45);
        //当前值
        String kpaN = data.substring(49,57);

        //报警类型
        String alarmTypeName = "";
        //报警内容
        String content = "";
        //消防支队数据
        String alarmStr = "";
        //报警表示
        boolean alarmFlag = false;
        JSONObject jsonParamItemMap = new JSONObject();
        //imei号，即应用平台的设备号
        jsonParamItemMap.put("number", number);
        //检测项数值
        Map<String, String> itemMap = getItme(jsonParamItemMap);
        if (itemMap.isEmpty()) {
            return RespEntity.fail("设备不存在!");
        }
        double dbMpa = 0;
        //正常数据信息
        JSONObject jSONObject = new JSONObject();
        JSONArray jSONArray = new JSONArray();
        if (deviceType.equals("902")) {//液压
            //报警值
            dbMpa = Double.parseDouble(kpaN) / 1000;
            if (dbMpa > Double.parseDouble(itemMap.get("液压报警;max"))) {
                alarmFlag = true;
                alarmTypeName = "液压报警";
                content = "水压高于上限阀值 " + "报警值:" + dbMpa + "MPa";
                alarmStr = "3002" + ";;" + dbMpa + ";;" + "水压异常";
            }else if (dbMpa < Double.parseDouble(itemMap.get("液压报警;min"))){
                alarmFlag = true;
                alarmTypeName = "液压报警";
                content = "水压低于下限阀值 " + "报警值:" + dbMpa + "MPa";
                alarmStr = "3002" + ";;" + dbMpa + ";;" + "水压异常";
            }
            jSONObject.put("name", "水压");
            jSONObject.put("value", dbMpa);
            jSONArray.add(jSONObject);

        } else {//液位
            //报警值
            dbMpa = Double.parseDouble(kpaN) / 10000;
            if (dbMpa < Double.parseDouble(itemMap.get("液位报警;min"))) {
                alarmTypeName = "液位报警";
                content = "水位报警 " + "报警值:" + dbMpa + "m";
                alarmFlag = true;
                alarmStr = "3102" + ";;" + dbMpa + ";;" + "水位异常";
            }
            jSONObject.put("name", "当前水位");
            jSONObject.put("value", dbMpa);
            jSONArray.add(jSONObject);

        }
        JSONObject jsonParamN = new JSONObject();
        jsonParamN.put("number", number);
        //为报警
        if (alarmFlag) {
            boolean insertAlarmFlag = false;
            //查询这个设备号这种类型的报警上次报警时间，如果时间间隔在2小时以内，不报警
            List<AlarmRecord> alarmList = alarmRecordMapper.selectList(new QueryWrapper<AlarmRecord>().eq("number", number).eq("type", alarmTypeName));
            if (alarmList.isEmpty()) {//没有记录时添加
                AlarmRecord alarmRecord = new AlarmRecord();
                alarmRecord.setNumber(number);
                alarmRecord.setTime(DateUtil.now());
                alarmRecord.setType(alarmTypeName);
                alarmRecordMapper.insert(alarmRecord);
                insertAlarmFlag = true;
            } else {//有记录时判断加修改
                AlarmRecord alarmRecord = alarmList.get(0);
                String times = alarmRecord.getTime();
                SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                boolean timeFlag = DateUtils.judgmentDate(times,0.5);
                if (timeFlag) {
                    alarmRecord.setTime(DateUtil.now());
                    alarmRecordMapper.update(alarmRecord, new QueryWrapper<AlarmRecord>().eq("number", number).eq("type", alarmTypeName));
                    insertAlarmFlag = true;
                }
            }
            if (insertAlarmFlag) {
                //存储在数据库
                FirewatersAlarmDeviceDataChanged firewatersAlarmDeviceDataChanged = new FirewatersAlarmDeviceDataChanged();
                firewatersAlarmDeviceDataChanged.setId(UUID.randomUUID().toString());
                firewatersAlarmDeviceDataChanged.setJsondata(jsonParam.toString());
                firewatersAlarmDeviceDataChangedMapper.insert(firewatersAlarmDeviceDataChanged);
                jsonParamN.put("interfaceType", "1");
                jsonParamN.put("number", number);
                jsonParamN.put("content", content);
                jsonParamN.put("alarmTypeName", alarmTypeName);
                jsonParamN.put("alarmtime", time);
                jsonParamN.put("deviceClassify", 2);
                jsonParamN.put("alarmStr", alarmStr);
                fireFightingiot(jsonParamN, "communication", "notificationAlarmHandel", "alarmInfo");
                //异步更新设备状态
                jsonParamN.put("state","2");
                asyncService.updateDeviceCurrentState(jsonParamN);
            }
        }else {
            //异步更新设备状态
            jsonParamN.put("state","1");
            asyncService.updateDeviceCurrentState(jsonParamN);
        }
        //存储在数据库
        FirewatersNormalDeviceDataChanged firewatersNormalDeviceDataChanged = new FirewatersNormalDeviceDataChanged();
        firewatersNormalDeviceDataChanged.setId(UUID.randomUUID().toString());
        firewatersNormalDeviceDataChanged.setJsondata(jsonParam.toString());
        firewatersNormalDeviceDataChangedMapper.insert(firewatersNormalDeviceDataChanged);
        //rest调用平时数据添加接口：
        jsonParamN.put("paraminfo", jSONArray);
        jsonParamN.put("time", time);
        //return RespEntity.success(jsonParamN);
        fireFightingiot(jsonParamN, "firefightingiot_data", "normalInfo", "device");
        //异步更新物联网卡号
        jsonParamN.put("iccid",hccid);
        asyncService.update_ICCID(jsonParamN);
        //异步维护水设备最新一包数据
        asyncService.updateWaterDeviceValue(jsonParamN);
        //解析数据结束-------------------------------------------------------------------------------------------------------
        return RespEntity.success();
    }

    /**
     * @Author YangYu
     * @Description 水柱箱体（京电云）
     * @Date Created in 10:14 2023/2/4
     * @Param [jsonParam, data, service]
     */
    public RespEntity waterColumnBox(JSONObject jsonParam) throws Exception {
        //数据404055aa1000000101000001100110011001ea01c20096005a006401900040400014000000eb2323
        String data = jsonParam.getStr("code");
        //数据更新
        JSONObject updateWaterColumnBoxDataJSON = new JSONObject();
        //设备号
        String number = data.substring(8,16);
        updateWaterColumnBoxDataJSON.put("number",number);
        //设备ID
        String deviceId = jsonParam.getStr("dev_id");
        updateWaterColumnBoxDataJSON.put("deviceId",deviceId);
        // 小数点位置
        int decimal = hexToInt(data.substring(68,70));
        // 实时数据正负标记
        int sign = hexToInt(data.substring(70,72));
        //实时液位
        BigDecimal level = new BigDecimal(hexToInt(data.substring(18,22))).movePointLeft(decimal);
        String levels = level.toString();
        if (sign == 1){
            levels = "-"+levels;
        }
        updateWaterColumnBoxDataJSON.put("waterLevel",levels);
        //量程下限
        String lowerRangeLimit = data.substring(22,26);
        BigDecimal lowerRangeLimits = new BigDecimal(hexToInt(lowerRangeLimit)).movePointLeft(decimal);
        updateWaterColumnBoxDataJSON.put("lrv",lowerRangeLimits);
        //量程上限
        String upperRangeLimit = data.substring(26,30);
        BigDecimal upperRangeLimits = new BigDecimal(hexToInt(upperRangeLimit)).movePointLeft(decimal);
        updateWaterColumnBoxDataJSON.put("upperRangeLimit",upperRangeLimits);
        //百分比
        String percentage = data.substring(30,34);
        Integer percentages = hexToInt(percentage);
        updateWaterColumnBoxDataJSON.put("percentage",percentages);
        //上上限报警设定值
        String upperLimitAlarmSettingValues = data.substring(34,38);
        BigDecimal upperLimitAlarmSetting_Values = new BigDecimal(hexToInt(upperLimitAlarmSettingValues)).movePointLeft(decimal);
        updateWaterColumnBoxDataJSON.put("upperLimitAlarmSettingValues",upperLimitAlarmSetting_Values);
        //上限报警设定值
        String upperLimitAlarmSettingValue = data.substring(38,42);
        BigDecimal upperLimitAlarmSetting_Value = new BigDecimal(hexToInt(upperLimitAlarmSettingValue)).movePointLeft(decimal);
        updateWaterColumnBoxDataJSON.put("upperLimitAlarmSettingValue",upperLimitAlarmSetting_Value);
        //下限报警设定值
        String lowerLimitAlarmSetPoint = data.substring(42,46);
        BigDecimal lowerLimitAlarmSet_Point = new BigDecimal(hexToInt(lowerLimitAlarmSetPoint)).movePointLeft(decimal);
        updateWaterColumnBoxDataJSON.put("lowerLimitAlarmSetPoint",lowerLimitAlarmSet_Point);
        //下下限报警设定值
        String lowerLimitAlarmSetPoints = data.substring(46,50);
        BigDecimal lowerLimitAlarmSet_Points = new BigDecimal(hexToInt(lowerLimitAlarmSetPoints)).movePointLeft(decimal);
        updateWaterColumnBoxDataJSON.put("lowerLimitAlarmSetPoints",lowerLimitAlarmSet_Points);
        //启动值
        String startValue = data.substring(50,54);
        BigDecimal startValues = new BigDecimal(hexToInt(startValue)).movePointLeft(decimal);
        updateWaterColumnBoxDataJSON.put("startValue",startValues);
        //停止值
        String stopValue = data.substring(54,58);
        BigDecimal stopValues = new BigDecimal(hexToInt(stopValue)).movePointLeft(decimal);
        updateWaterColumnBoxDataJSON.put("stopValue",stopValues);
        //报警标识
        String alarm_flag = hexToBinaryString(data.substring(58,60));
        //手自动状态
        String manualAutomaticState = data.substring(60,62);
        if (manualAutomaticState.equals("01")){
            updateWaterColumnBoxDataJSON.put("manualAutomaticState",1);
        }else if (manualAutomaticState.equals("02")){
            updateWaterColumnBoxDataJSON.put("manualAutomaticState",2);
        }else {
            updateWaterColumnBoxDataJSON.put("manualAutomaticState",3);
        }
        //控制输出状态
        String controlOutputStatus = data.substring(62,64);
        //信号百分比
        String signalPercentage = data.substring(64,66);
        Integer signalPercentages = hexToInt(signalPercentage);
        updateWaterColumnBoxDataJSON.put("signalPercentage",signalPercentages);
        //数据更新
        asyncService.updateWaterColumnBoxData(updateWaterColumnBoxDataJSON);
        //时间
        String time = DateUtil.now();
        //报警类型
        String alarmTypeName = "";
        //报警内容
        String content = "";
        //报警表示
        boolean alarmFlag = false;
        //报警
        if (alarm_flag.charAt(0) == '1') {
            alarmFlag = true;
            alarmTypeName = "液位报警";
            content = "下下限报警 " + "报警值:" + lowerLimitAlarmSet_Points + "m";
        }else if (alarm_flag.charAt(1) == '1'){
            alarmFlag = true;
            alarmTypeName = "液位报警";
            content = "下限报警 " + "报警值:" + lowerLimitAlarmSet_Point + "m";
        }else if (alarm_flag.charAt(2) == '1'){
            alarmFlag = true;
            alarmTypeName = "液位报警";
            content = "上限报警 " + "报警值:" + upperLimitAlarmSetting_Value + "m";
        }else if (alarm_flag.charAt(3) == '1'){
            alarmFlag = true;
            alarmTypeName = "液位报警";
            content = "上上限报警 " + "报警值:" + upperLimitAlarmSetting_Values + "m";
        }
        JSONObject jsonParamN = new JSONObject();
        jsonParamN.put("number", number);
        //为报警
        if (alarmFlag) {
//            boolean insertAlarmFlag = false;
//            //查询这个设备号这种类型的报警上次报警时间，如果时间间隔在2小时以内，不报警
//            List<AlarmRecord> alarmList = alarmRecordMapper.selectList(new QueryWrapper<AlarmRecord>().eq("number", number).eq("type", alarmTypeName));
//            if (alarmList.isEmpty()) {//没有记录时添加
//                AlarmRecord alarmRecord = new AlarmRecord();
//                //alarmRecord.setNumber(number);
//                alarmRecord.setTime(DateUtil.now());
//                alarmRecord.setType(alarmTypeName);
//                alarmRecordMapper.insert(alarmRecord);
//                insertAlarmFlag = true;
//            } else {//有记录时判断加修改
//                AlarmRecord alarmRecord = alarmList.get(0);
//                String times = alarmRecord.getTime();
//                SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//                boolean timeFlag = getDatePoor(new Date(), simpleDateFormat.parse(times), 0.5);
//                if (timeFlag) {
//                    alarmRecord.setTime(DateUtil.now());
//                    alarmRecordMapper.update(alarmRecord, new QueryWrapper<AlarmRecord>().eq("number", number).eq("type", alarmTypeName));
//                    insertAlarmFlag = true;
//                }
//            }
            //if (insertAlarmFlag) {
                jsonParamN.put("interfaceType", "1");
                jsonParamN.put("content", content);
                jsonParamN.put("alarmTypeName", alarmTypeName);
                jsonParamN.put("alarmtime", time);
                jsonParamN.put("deviceClassify", 2);
                fireFightingiot(jsonParamN, "communication", "notificationAlarmHandel", "alarmInfo");
                //异步更新设备状态
                jsonParamN.put("state","2");
                asyncService.updateDeviceCurrentState(jsonParamN);
            //}
        }else {
            jsonParamN.put("state","1");
            asyncService.updateDeviceCurrentState(jsonParamN);
        }
        //正常数据信息
        JSONObject jSONObject = new JSONObject();
        JSONArray jSONArray = new JSONArray();
        jSONObject.put("name", "当前水位");
        jSONObject.put("value", levels);
        jSONArray.add(jSONObject);
        //rest调用平时数据添加接口：
        jsonParamN.put("paraminfo", jSONArray);
        jsonParamN.put("time", time);
        //return RespEntity.success(jsonParamN);
        fireFightingiot(jsonParamN, "firefightingiot_data", "normalInfo", "device");
        //大数据库
        jsonParamN.put("dataType", "2");
        fireFightingiot(jsonParamN, "communication", "notificationAlarmHandel", "alarmInfo");
        //asyncService.updateWaterDeviceValue(jsonParamN);
        //解析数据结束-------------------------------------------------------------------------------------------------------
        return RespEntity.success();
    }
    /**
     * @Author YangYu
     * @Description 无线仪表（京电云@正润NB（电信））
     * @Date Created in 10:14 2023/2/4
     * @Param [jsonParam, data, service]
     */
    public RespEntity wirelessInstrument(JSONObject jsonParam) throws Exception {
        //数据00005a523130315631304938363736323830373134393132363048383938363034443831303233433032313338343858303350463030373338443342325539395332324f5a30313630304c5a3030313030
        //String data = jsonParam.getStr("code");
        //data = data.substring(4,data.length());
        // 16进制转ASCII码 ZR101V10I867628071491260H898604D81023C0213848X03PF00738D3B2U99S22OZ01600LZ00100
        //String asciiCode = HexToASCIIUtils.convertHexToString(data);
        try {
            String asciiCode = convertHexToString(HexUtil.encodeHexStr(Base64Decoder.decode(jsonParam.getJSONObject("payload").getStr("APPdata"))));
            //数据更新
            JSONObject updateWaterColumnBoxDataJSON = new JSONObject();
            // 设备版本
            double deviceVersion = Integer.parseInt(asciiCode.substring(6,8)) * 0.1;
            updateWaterColumnBoxDataJSON.put("version",deviceVersion);
            //设备号
            String number = asciiCode.substring(9,24);
            updateWaterColumnBoxDataJSON.put("number",number);
            //设备ID
            String deviceId = jsonParam.getStr("deviceId");
            updateWaterColumnBoxDataJSON.put("deviceId",deviceId);
            // 电话卡号
            String hccId = asciiCode.substring(25,45);
            // 报警类型 10：正常 02:电量不足 03:低报警 13:低报警恢复 04:高报警 14:高报警恢复 05:波动报警 15：波动修复
            String alarmType = asciiCode.substring(46,48);
            // 小数点位置
            int decimal = Integer.parseInt(asciiCode.substring(56,57));
            // 实时数据正负标记
            String sign = asciiCode.substring(48,50);
            //实时数据
            BigDecimal timeData = new BigDecimal(Integer.parseInt(asciiCode.substring(50,55))).movePointLeft(decimal);
            //正负数
            String timeDataZF = timeData.toString();
            if (sign.equals("PF")){
                timeDataZF = "-"+timeDataZF;
            }
            updateWaterColumnBoxDataJSON.put("waterLevel",timeDataZF);
            // 单位 1:Kpa  2:Mpa  3:bar  4:℃  5:m  6:psi  7:mm  8:kgf/cm³
            String unit = asciiCode.substring(58,59);
            if (unit.equals("1")){
                updateWaterColumnBoxDataJSON.put("unit","Kpa");
                unit = "Kpa";
            }else if (unit.equals("2")){
                updateWaterColumnBoxDataJSON.put("unit","Mpa");
                unit = "Mpa";
            }else if (unit.equals("3")){
                updateWaterColumnBoxDataJSON.put("unit","bar");
                unit = "bar";
            }else if (unit.equals("4")){
                updateWaterColumnBoxDataJSON.put("unit","℃");
                unit = "℃";
            }else if (unit.equals("5")){
                updateWaterColumnBoxDataJSON.put("unit","m");
                unit = "m";
            }else if (unit.equals("6")){
                updateWaterColumnBoxDataJSON.put("unit","psi");
                unit = "psi";
            }else if (unit.equals("7")){
                updateWaterColumnBoxDataJSON.put("unit","mm");
                unit = "mm";
            }else if (unit.equals("8")){
                updateWaterColumnBoxDataJSON.put("unit","kgf/cm³");
                unit = "kgf/cm³";
            }
            // 电量
            String electricity = asciiCode.substring(60,62);
            updateWaterColumnBoxDataJSON.put("electricity",electricity);
            //信号百分比 ZR101V10I867628071491260H898604D81023C0213848X03PF00738D3B2U99S22OZ01600LZ00100
            String signalPercentage = asciiCode.substring(63,65);
            updateWaterColumnBoxDataJSON.put("signalPercentage",signalPercentage);

            //报警上限
            sign = asciiCode.substring(66,67);
            String upperLimitAlarmSettingValue = asciiCode.substring(67,72);
            BigDecimal upperLimitAlarmSetting_Value = new BigDecimal(upperLimitAlarmSettingValue).movePointLeft(decimal);
            if (sign.equals("F")){
                updateWaterColumnBoxDataJSON.put("upperLimitAlarmSettingValue","-"+upperLimitAlarmSetting_Value);
            }else {
                updateWaterColumnBoxDataJSON.put("upperLimitAlarmSettingValue",upperLimitAlarmSetting_Value);
            }

            //报警下限
            sign = asciiCode.substring(73,74);
            String lowerLimitAlarmSetPoint = asciiCode.substring(74,79);
            BigDecimal lowerLimitAlarmSet_Point = new BigDecimal(lowerLimitAlarmSetPoint).movePointLeft(decimal);

            if (sign.equals("F")){
                updateWaterColumnBoxDataJSON.put("lowerLimitAlarmSetPoint","-"+lowerLimitAlarmSet_Point);
            }else {
                updateWaterColumnBoxDataJSON.put("lowerLimitAlarmSetPoint",lowerLimitAlarmSet_Point);
            }

            //数据更新
            asyncService.updateWirelessInstrumentData(updateWaterColumnBoxDataJSON);
            //时间
            String time = DateUtil.now();
            //报警类型
            String alarmTypeName = "";
            //报警内容
            String content = "";
            //报警表示
            boolean alarmFlag = false;
            //报警
            if (alarmType.equals("02")) {
                alarmFlag = true;
                alarmTypeName = "电量不足";
                content = "电量不足 " + "报警值:" + electricity + "%";
            }else if (alarmType.equals("03")){
                alarmFlag = true;
                alarmTypeName = "低报警";
                content = "低报警 " + "报警值:" + timeDataZF + unit;
            }else if (alarmType.equals("04")){
                alarmFlag = true;
                alarmTypeName = "高报警";
                content = "高报警 " + "报警值:" + timeDataZF + unit;
            }
            JSONObject jsonParamN = new JSONObject();
            jsonParamN.put("number", number);
            //为报警
            if (alarmFlag) {
//            boolean insertAlarmFlag = false;
//            //查询这个设备号这种类型的报警上次报警时间，如果时间间隔在2小时以内，不报警
//            List<AlarmRecord> alarmList = alarmRecordMapper.selectList(new QueryWrapper<AlarmRecord>().eq("number", number).eq("type", alarmTypeName));
//            if (alarmList.isEmpty()) {//没有记录时添加
//                AlarmRecord alarmRecord = new AlarmRecord();
//                //alarmRecord.setNumber(number);
//                alarmRecord.setTime(DateUtil.now());
//                alarmRecord.setType(alarmTypeName);
//                alarmRecordMapper.insert(alarmRecord);
//                insertAlarmFlag = true;
//            } else {//有记录时判断加修改
//                AlarmRecord alarmRecord = alarmList.get(0);
//                String times = alarmRecord.getTime();
//                SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//                boolean timeFlag = getDatePoor(new Date(), simpleDateFormat.parse(times), 0.5);
//                if (timeFlag) {
//                    alarmRecord.setTime(DateUtil.now());
//                    alarmRecordMapper.update(alarmRecord, new QueryWrapper<AlarmRecord>().eq("number", number).eq("type", alarmTypeName));
//                    insertAlarmFlag = true;
//                }
//            }
                //if (insertAlarmFlag) {
                jsonParamN.put("interfaceType", "1");
                jsonParamN.put("content", content);
                jsonParamN.put("alarmTypeName", alarmTypeName);
                jsonParamN.put("alarmtime", time);
                jsonParamN.put("deviceClassify", 2);
                fireFightingiot(jsonParamN, "communication", "notificationAlarmHandel", "alarmInfo");
                //异步更新设备状态
                jsonParamN.put("state","2");
                asyncService.updateDeviceCurrentState(jsonParamN);
                //}
            }else {
                jsonParamN.put("state","1");
                asyncService.updateDeviceCurrentState(jsonParamN);
            }
            //正常数据信息
            JSONObject jSONObject = new JSONObject();
            JSONArray jSONArray = new JSONArray();
            jSONObject.put("name", "当前水位");
            jSONObject.put("value", timeDataZF);
            jSONArray.add(jSONObject);
            //rest调用平时数据添加接口：
            jsonParamN.put("paraminfo", jSONArray);
            jsonParamN.put("time", time);
            //return RespEntity.success(jsonParamN);
            fireFightingiot(jsonParamN, "firefightingiot_data", "normalInfo", "device");
            //大数据库
            jsonParamN.put("dataType", "2");
            fireFightingiot(jsonParamN, "communication", "notificationAlarmHandel", "alarmInfo");
            //asyncService.updateWaterDeviceValue(jsonParamN);
        }catch (Exception e){
            System.out.println("wirelessInstrument:+++"+e);
        }

        //解析数据结束-------------------------------------------------------------------------------------------------------
        return RespEntity.success();
    }

    /**
     * @Author YangYu
     * @Description 4g仪表（京电云@正润4G（tcp））
     * @Date Created in 10:14 2023/2/4
     * @Param [jsonParam, data, service]
     */
    public RespEntity zrMeter(JSONObject jsonParam) throws Exception {
        try {
            //数据7f7f5a5232303156313049383638383932303736373434353635483839383631313233323037303932313436303238583130505a3030333538443242325539395332354f5a30303230304c5a3030303530
            String data = jsonParam.getStr("code");
            data = data.substring(4,data.length());
            // 16进制转ASCII码 ZR101V10I867628071491260H898604D81023C0213848X03PF00738D3B2U99S22OZ01600LZ00100
            String asciiCode = HexToASCIIUtils.convertHexToString(data);
            //数据更新
            JSONObject updateWaterColumnBoxDataJSON = new JSONObject();
            // 设备版本
            double deviceVersion = Integer.parseInt(asciiCode.substring(6,8)) * 0.1;
            updateWaterColumnBoxDataJSON.put("version",deviceVersion);
            //设备号
            String number = asciiCode.substring(9,24);
            updateWaterColumnBoxDataJSON.put("number",number);
            //设备ID
            String deviceId = jsonParam.getStr("dev_id");
            updateWaterColumnBoxDataJSON.put("deviceId",deviceId);
            // 电话卡号
            String hccId = asciiCode.substring(25,45);
            // 报警类型 10：正常 02:电量不足 03:低报警 13:低报警恢复 04:高报警 14:高报警恢复 05:波动报警 15：波动修复
            String alarmType = asciiCode.substring(46,48);
            // 小数点位置
            int decimal = Integer.parseInt(asciiCode.substring(56,57));
            // 实时数据正负标记
            String sign = asciiCode.substring(48,50);
            //实时数据
            BigDecimal timeData = new BigDecimal(Integer.parseInt(asciiCode.substring(50,55))).movePointLeft(decimal);
            //正负数
            String timeDataZF = timeData.toString();
            if (sign.equals("PF")){
                timeDataZF = "-"+timeDataZF;
            }
            updateWaterColumnBoxDataJSON.put("waterLevel",timeDataZF);
            // 单位 1:Kpa  2:Mpa  3:bar  4:℃  5:m  6:psi  7:mm  8:kgf/cm³
            String unit = asciiCode.substring(58,59);
            if (unit.equals("1")){
                updateWaterColumnBoxDataJSON.put("unit","Kpa");
                unit = "Kpa";
            }else if (unit.equals("2")){
                updateWaterColumnBoxDataJSON.put("unit","Mpa");
                unit = "Mpa";
            }else if (unit.equals("3")){
                updateWaterColumnBoxDataJSON.put("unit","bar");
                unit = "bar";
            }else if (unit.equals("4")){
                updateWaterColumnBoxDataJSON.put("unit","℃");
                unit = "℃";
            }else if (unit.equals("5")){
                updateWaterColumnBoxDataJSON.put("unit","m");
                unit = "m";
            }else if (unit.equals("6")){
                updateWaterColumnBoxDataJSON.put("unit","psi");
                unit = "psi";
            }else if (unit.equals("7")){
                updateWaterColumnBoxDataJSON.put("unit","mm");
                unit = "mm";
            }else if (unit.equals("8")){
                updateWaterColumnBoxDataJSON.put("unit","kgf/cm³");
                unit = "kgf/cm³";
            }
            // 电量
            String electricity = asciiCode.substring(60,62);
            updateWaterColumnBoxDataJSON.put("electricity",electricity);
            //信号百分比 ZR101V10I867628071491260H898604D81023C0213848X03PF00738D3B2U99S22OZ01600LZ00100
            String signalPercentage = asciiCode.substring(63,65);
            updateWaterColumnBoxDataJSON.put("signalPercentage",signalPercentage);

            //报警上限
            sign = asciiCode.substring(66,67);
            String upperLimitAlarmSettingValue = asciiCode.substring(67,72);
            BigDecimal upperLimitAlarmSetting_Value = new BigDecimal(upperLimitAlarmSettingValue).movePointLeft(decimal);
            if (sign.equals("F")){
                updateWaterColumnBoxDataJSON.put("upperLimitAlarmSettingValue","-"+upperLimitAlarmSetting_Value);
            }else {
                updateWaterColumnBoxDataJSON.put("upperLimitAlarmSettingValue",upperLimitAlarmSetting_Value);
            }

            //报警下限
            sign = asciiCode.substring(73,74);
            String lowerLimitAlarmSetPoint = asciiCode.substring(74,79);
            BigDecimal lowerLimitAlarmSet_Point = new BigDecimal(lowerLimitAlarmSetPoint).movePointLeft(decimal);

            if (sign.equals("F")){
                updateWaterColumnBoxDataJSON.put("lowerLimitAlarmSetPoint","-"+lowerLimitAlarmSet_Point);
            }else {
                updateWaterColumnBoxDataJSON.put("lowerLimitAlarmSetPoint",lowerLimitAlarmSet_Point);
            }

            //数据更新
            asyncService.updateWirelessInstrumentData(updateWaterColumnBoxDataJSON);
            //时间
            String time = DateUtil.now();
            //报警类型
            String alarmTypeName = "";
            //报警内容
            String content = "";
            //报警表示
            boolean alarmFlag = false;
            //报警
            if (alarmType.equals("02")) {
                alarmFlag = true;
                alarmTypeName = "电量不足";
                content = "电量不足 " + "报警值:" + electricity + "%";
            }else if (alarmType.equals("03")){
                alarmFlag = true;
                alarmTypeName = "低报警";
                content = "低报警 " + "报警值:" + timeDataZF + unit;
            }else if (alarmType.equals("04")){
                alarmFlag = true;
                alarmTypeName = "高报警";
                content = "高报警 " + "报警值:" + timeDataZF + unit;
            }
            JSONObject jsonParamN = new JSONObject();
            jsonParamN.put("number", number);
            //为报警
            if (alarmFlag) {
                jsonParamN.put("interfaceType", "1");
                jsonParamN.put("content", content);
                jsonParamN.put("alarmTypeName", alarmTypeName);
                jsonParamN.put("alarmtime", time);
                jsonParamN.put("deviceClassify", 2);
                fireFightingiot(jsonParamN, "communication", "notificationAlarmHandel", "alarmInfo");
                //异步更新设备状态
                jsonParamN.put("state","2");
                asyncService.updateDeviceCurrentState(jsonParamN);
            }else {
                jsonParamN.put("state","1");
                asyncService.updateDeviceCurrentState(jsonParamN);
            }
            //正常数据信息
            JSONObject jSONObject = new JSONObject();
            JSONArray jSONArray = new JSONArray();
            jSONObject.put("name", "当前水位");
            jSONObject.put("value", timeDataZF);
            jSONArray.add(jSONObject);
            //rest调用平时数据添加接口：
            jsonParamN.put("paraminfo", jSONArray);
            jsonParamN.put("time", time);
            //return RespEntity.success(jsonParamN);
            fireFightingiot(jsonParamN, "firefightingiot_data", "normalInfo", "device");
            //大数据库
            jsonParamN.put("dataType", "2");
            fireFightingiot(jsonParamN, "communication", "notificationAlarmHandel", "alarmInfo");
            //asyncService.updateWaterDeviceValue(jsonParamN);
        }catch (Exception e){
            System.out.println("wirelessInstrument:+++"+e);
        }

        //解析数据结束-------------------------------------------------------------------------------------------------------
        return RespEntity.success();
    }
    /**
     * @Author YangYu
     * @Description 十六进制转二进制字符串
     * @Date Created in 14:07 2021/11/24
     * @Param [hex]
     */

    public static String hexToBinaryString(String hex) {
        String str = Integer.toBinaryString(Integer.parseInt(hex,16));
        if(str.length() == 1){
            str = "000" + str;
        }else if(str.length() == 2){
            str = "00" + str;
        }else if(str.length() == 3){
            str = "0" + str;
        }
        return str;
    }

    /**
     * @Author YangYu
     * @Description 十六进制转十进制
     * @Date Created in 16:37 2022/1/12
     * @Param [hex]
     */

    public static int hexToInt(String hex){
        if (hex.length() < 1){
            return 0;
        }else {
            return Integer.parseInt(hex,16);
        }
    }

    public static void main(String[] args) {
        //数据
        String data = convertHexToString("7f7f5a5232303156313049383638383932303736373434353635483839383631313233323037303932313436303238583130505a3030333538443242325539395332354f5a30303230304c5a3030303530");

        System.out.println(data);
    }


    /**
     * 将时间转化成北京时间
     *
     * @param str
     * @return
     * @throws Exception
     */
    public String contextLoads(String str) throws Exception {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd'T'HHmmss'Z'");
        SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
        Date date = sdf.parse(str);
        String strN = sdf2.format(date);
        return strN;
    }
    /**
     * 将毫秒转化为日期(格式:yyyy-MM-dd hh:mm:ss)
     *
     * @param l
     * @return
     * @throws Exception
     */
    public String contextLoads(Long l) throws Exception {

        SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss SSS");
        Date date = new Date(l);
        String str1 = sdf1.format(date);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date2 = sdf.parse(str1);
        String str2 = sdf.format(date2);
        return str2;
    }

    /**
     * 16进制 转 ASCII码
     * @param “3030313030312d30303300000000000000000000”
     * @return 001001-003
     */
    public static String convertHexToString(String hex) {

        StringBuilder sb = new StringBuilder();
        StringBuilder temp = new StringBuilder();

        //49204c6f7665204a617661 split into two characters 49, 20, 4c...
        for (int i = 0; i < hex.length() - 1; i += 2) {

            //grab the hex in pairs
            String output = hex.substring(i, (i + 2));
            if (!output.equals("00")) {
                //convert hex to decimal
                int decimal = Integer.parseInt(output, 16);
                //convert the decimal to character
                sb.append((char) decimal);

                temp.append(decimal);
            }
        }

        return sb.toString();

    }
}
